home *** CD-ROM | disk | FTP | other *** search
/ AMIGA-CD 2 / Amiga-CD - Volume 2.iso / gepackte_disketten / 1994 / 08_94_5.dms / 08_94_5.adf / term-4.0-Source.lha / termResponse.c < prev    next >
C/C++ Source or Header  |  1994-07-01  |  2KB  |  114 lines

  1. /*
  2. **    termResponse.c
  3. **
  4. **    Signal event handling routines
  5. **
  6. **    Copyright © 1990-1994 by Olaf `Olsen' Barthel
  7. **        All Rights Reserved
  8. */
  9.  
  10. #include "termGlobal.h"
  11.  
  12.     /* Yet another function pointer. */
  13.  
  14. typedef BYTE (* RESPONSE)(VOID);
  15.  
  16.     /* Signal response table entry. */
  17.  
  18. struct SignalResponseInfo
  19. {
  20.     RESPONSE    Routine;
  21.     ULONG        Mask;
  22. };
  23.  
  24.     /* Signal response table. */
  25.  
  26. STATIC struct SignalResponseInfo    ResponseTable[7];
  27. STATIC WORD                ResponseCount;
  28. STATIC ULONG                ResponseMask;
  29.  
  30.     /* AddResponse(RESPONSE Routine,ULONG Mask):
  31.      *
  32.      *    Register a signal response routine.
  33.      */
  34.  
  35. STATIC VOID __regargs
  36. AddResponse(RESPONSE Routine,ULONG Mask)
  37. {
  38.     ResponseTable[ResponseCount] . Routine    = Routine;
  39.     ResponseTable[ResponseCount] . Mask    = Mask;
  40.  
  41.     ResponseMask |= Mask;
  42.  
  43.     ResponseCount++;
  44. }
  45.  
  46.     /* HandleResponse():
  47.      *
  48.      *    Register routines and corresponding signals,
  49.      *    wait for events and process them.
  50.      */
  51.  
  52. VOID
  53. HandleResponse()
  54. {
  55.     register ULONG    SignalSet;
  56.     register BYTE    Running;
  57.     register WORD    i;
  58.  
  59.     ResponseMask    = XEM_Signal;
  60.     ResponseCount    = 0;
  61.  
  62.     AddResponse((RESPONSE)HandleSerialCheck,SIG_CHECK);
  63.  
  64.     if(WorkbenchPort)
  65.         AddResponse((RESPONSE)HandleWorkbenchWindow,SIG_WORKBENCH);
  66.  
  67.     if(ReadPort && Status != STATUS_HOLDING && ProcessIO)
  68.         AddResponse(HandleSerial,SIG_SERIAL);
  69.  
  70.     if(OwnDevUnitBase && !Config -> SerialConfig -> Shared && OwnDevBit != -1)
  71.         AddResponse(HandleOwnDevUnit,1L << OwnDevBit);
  72.  
  73.     AddResponse(HandleWindow,SIG_WINDOW);
  74.  
  75.     if(TermRexxPort)
  76.         AddResponse(HandleRexx,SIG_REXX);
  77.  
  78.     AddResponse(HandleQueueMsg,SIG_QUEUE);
  79.  
  80.         /* Wait for events. */
  81.  
  82.     if(HostReadBuffer || DataHold)
  83.     {
  84.         if(ReadPort && Status != STATUS_HOLDING)
  85.             SignalSet = CheckSignal(ResponseMask) | SIG_SERIAL;
  86.         else
  87.             SignalSet = CheckSignal(ResponseMask);
  88.     }
  89.     else
  90.         SignalSet = Wait(ResponseMask);
  91.  
  92.     if(SignalSet & XEM_Signal)
  93.         HandleExternalEmulation();
  94.  
  95.     FOREVER
  96.     {
  97.         for(i = 0, Running = FALSE ; !MainTerminated && i < ResponseCount ; i++)
  98.         {
  99.             if(SignalSet & ResponseTable[i] . Mask)
  100.             {
  101.                 if((*ResponseTable[i] . Routine)())
  102.                     Running = TRUE;
  103.                 else
  104.                     SignalSet &= ~ResponseTable[i] . Mask;
  105.             }
  106.         }
  107.  
  108.         if(Running && !MainTerminated)
  109.             SignalSet |= SetSignal(0,ResponseMask) & ResponseMask;
  110.         else
  111.             break;
  112.     }
  113. }
  114.